package cc.wenshixin.service;

import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import cc.wenshixin.dao.CustomerDao;
import cc.wenshixin.entity.Customer;
import cc.wenshixin.entity.Level;
import cc.wenshixin.entity.PageBean;

@Transactional
public class CustomerService {
	//属性注入
	private CustomerDao customerDao;
	public void setCustomerDao(CustomerDao customerDao) {
		this.customerDao = customerDao;
	}
	
	public void add(Customer customer) {
		customerDao.add(customer);
	}

	public List<Customer> findAll() {
		return customerDao.findAll();
	}

	public Customer findOne(int id) {
		return customerDao.findOne(id);
	}

	public void update(Customer customer) {
		customerDao.update(customer);
	}

	public void delete(Customer c) {
		customerDao.delete(c);
	}

	public List<Customer> findCondition(Customer customer) {
		return customerDao.findCondition(customer);
	}

	public PageBean listPage(Integer currentPage) {
		PageBean pageBean = new PageBean();
		pageBean.setCurrentPage(currentPage);
		int totalCount = customerDao.findCount();
		pageBean.setTotalCount(totalCount);
		int pageSize = 3;
		int totalPage = 0;
		if(totalCount % pageSize == 0) {
			totalPage = totalCount / pageSize;
		} else {
			totalPage = totalCount / pageSize + 1;
		}
		pageBean.setTotalPage(totalPage);
		int begin = (currentPage -1) * pageSize;
		List<Customer> list = customerDao.findPage(begin,pageSize);
		pageBean.setList(list);
		return pageBean;
	}

	public List<Customer> selectMoreCondition(Customer customer) {
		return customerDao.selectMoreCondition(customer);
	}

	public List<Level> findAllLevel() {
		return customerDao.findAllLevel();
	}

	public List findCountLevel() {
		return customerDao.findCountLevel();
	}

	public List findCountSource() {
		return customerDao.findCountSource();
	}
}
